package org.example.runningforum.mapper;// IUserMapper.java

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.runningforum.modle.User;

@Mapper
public interface IUserMapper {
    // 用户登录验证
    @Select("SELECT * FROM user WHERE username = #{username} AND is_deleted = 0")
    User selectUserByUsername( String username);



    // 添加新用户
    @Insert("INSERT INTO user (username, password, mobile) " +
            "VALUES (#{username}, #{password}, #{mobile})")
    int insertUser(User user);


    //根据用户id查询用户信息
    @Select("SELECT * FROM user WHERE user_id = #{userId} AND is_deleted = 0")
    User selectUserById(Integer userId);


    // 更新用户信息（包含用户名、密码、等级和手机号）
    @Update("UPDATE user SET username = #{username}, password = #{password}, mobile = #{mobile} " +
            "WHERE user_id = #{userId} AND is_deleted = 0")
    int updateUser(User user);

    // 逻辑删除用户
    @Update("UPDATE user SET is_deleted = 1 WHERE user_id = #{userId}")
    int deleteUser (Long userId);


    @Select("SELECT COUNT(*) AS user_count \n" +
            "FROM `user` \n" +
            "WHERE is_deleted = 0;")
    Integer selectUserCount();
}